package cn.edu.ujn.lab3.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.StringUtils;

import cn.edu.ujn.lab3.dao.Customer;
import cn.edu.ujn.lab3.dao.Orders;
import cn.edu.ujn.lab3.dao.OrdersMapper;
import cn.edu.ujn.lab3.utils.Page;

@Service("ordersService")
@Transactional
public class OrdersServiceImpl implements OrdersService {
	
	@Autowired
	private OrdersMapper ordersDao;

	@Override
	public Orders selectByCustId(Integer custId) {
		// TODO Auto-generated method stub
		return ordersDao.selectByCustId(custId);
	}

	@Override
	public Orders selectByNumber(Integer number) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public Page<Orders> findOrdersList(Integer page, Integer rows, String number,Integer custId){
		Orders orders = new Orders();
		if(!StringUtils.isNullOrEmpty(number)) {
			orders.setNumber(number);
		}
		orders.setCust_id(custId);
		
		orders.setStart((page-1) * rows);
		orders.setRows(rows);
		List<Orders> order = this.ordersDao.findAll(orders);
		// 查询总记录数
		Integer count = this.ordersDao.selectOrderListCount(orders);
		// 创建Page返回对象
		Page<Orders> result = new Page<Orders>();
		result.setPage(page);
		result.setRows(order);
		result.setSize(rows);
		result.setTotal(count);
		return result;

	}

	@Override
	public Integer selectOrderListCount(Orders order) {
		// TODO Auto-generated method stub
		return ordersDao.selectOrderListCount(order);
	}
	
	@Override
	public Orders selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return this.ordersDao.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKey(Orders row) {
		// TODO Auto-generated method stub
		return this.ordersDao.updateByPrimaryKey(row);
	}

	@Override
	public int updateByPrimaryKeySelective(Orders row) {
		// TODO Auto-generated method stub
		return this.ordersDao.updateByPrimaryKeySelective(row);
	}

	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return this.ordersDao.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Orders row) {
		// TODO Auto-generated method stub
		return this.ordersDao.insert(row);
	}

	@Override
	public int insertSelective(Orders row) {
		// TODO Auto-generated method stub
		return this.ordersDao.insertSelective(row);
	}


}
